<!-- 
    The Code By DayiTech FrontEnd
    Author:Han
    Created At 2018/05/05 14:20:39
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>排行榜</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/app.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style>
        body{
            padding:0;
            margin:0;
            background-color:white;
        }
        .brand_logo{
            max-width:100px;
            max-height:80px;
            margin-top:20px;
        }
        .title-box{
            text-align: center;
            overflow: hidden;
        }
        .title{
            font-size:40px;
            line-height:90px;
        }
        .title b{
            font-size:59.5px;
        }
        .rank-box{
            margin-bottom: 0;
            padding-bottom:0;
        }
        .rank-box .rank-body{
            margin:0 auto;
            width: 1040px;
            height: 140px;
            border-radius: 30px;
            background-color: #f2f6fc;
            box-shadow: 0px 4px 10px 0 rgba(151, 151, 151, 0.35);
        }
        .rank-box .rank-body:nth-child(1),.rank-box .rank-body:nth-child(2),.rank-box .rank-body:nth-child(3){
            height:220px;
        }
        .el-progress-bar__outer{
            background-color:#f2f6fc;
        }

        .rank-box .rank-body:nth-child(1),.rank-box .rank-body:nth-child(2),.rank-box .rank-body:nth-child(3){
            overflow: hidden;
            margin-bottom:20px;
        }
        .rank-box .rank-body:nth-child(1) .rank-title,.rank-box .rank-body:nth-child(2) .rank-title,.rank-box .rank-body:nth-child(3) .rank-title{
            font-size:60.2px;
            display: block;
            overflow: hidden;
        }
        .rank-box .rank-body:nth-child(2){
            background-color: #eeeeee;
        }
        .rank-box .rank-body:nth-child(2) .el-progress-bar__outer{
            background-color: #eeeeee;
        }
        .rank-box .rank-body:nth-child(1) .rank-title{
            color: #f56c6c;
        }
        .rank-box .rank-body:nth-child(2) .rank-title{
            color: #f5c66c;
        }
        .rank-box .rank-body:nth-child(3) .rank-title{
            color: #6cc3f5;
        }
        .rank-box .rank-body:nth-child(1) .rank-title span,.rank-box .rank-body:nth-child(2) .rank-title span,.rank-box .rank-body:nth-child(3) .rank-title span{
            line-height:240px;
        }
        .rank-box .rank-body:nth-child(1) .rank-title b,.rank-box .rank-body:nth-child(2) .rank-title b,.rank-box .rank-body:nth-child(3) .rank-title b{
            font-size:130px;
            line-height:240px;
        }
        .rank-box .rank-body:nth-child(1) .rank-img,.rank-box .rank-body:nth-child(2) .rank-img,.rank-box .rank-body:nth-child(3) .rank-img{
            width:140px;
            height:140px;
            margin-top:50px;
        }
        .rank-box .rank-body:nth-child(1) .rank-img img,.rank-box .rank-body:nth-child(2) .rank-img img,.rank-box .rank-body:nth-child(3) .rank-img img{
            max-width:140px;
            max-height:140px;
        }
        .rank-box .rank-body:nth-child(1) .rank-girard,.rank-box .rank-body:nth-child(2) .rank-girard,.rank-box .rank-body:nth-child(3) .rank-girard{
            font-size:60.8px;
            margin-bottom:40px;
            margin-top:20px;
        }
        .rank-box-four{
            padding:0;
        }
        .rank-box-four .rank-body{
            overflow: hidden;
            margin:0 auto;
            width: 1040px;
            height: 140px;
            border-radius: 30px;
            background-color: #f2f6fc;
            box-shadow: 0px 4px 10px 0 rgba(151, 151, 151, 0.35);
            margin-bottom:20px;
        }
        .rank-box-four .rank-body .rank-title{
            font-size:40.2px;
            display: block;
            overflow: hidden;
            color: #6cc3f5;
        }
        .rank-box-four .rank-body .rank-title span{
            line-height:140px;
        }
        .rank-box-four .rank-body .rank-title b{
            font-size:90px;
            line-height:140px;
        }
        .rank-box-four .rank-body .rank-img{
            width:80px;
            height:80px;
            margin-top:30px;
        }
        .rank-box-four .rank-body .rank-img img{
            max-width:80px;
            max-height:80px;
        }
        .rank-box-four .rank-body .rank-girard{
            font-size:28.8px;
            margin-bottom:20px;
            margin-top:20px;
        }
        .rank-box-four .rank-body:nth-child(odd) {
            background-color: #eeeeee;
        }
        .rank-box-four .rank-body:nth-child(odd) .el-progress-bar__outer{
            background-color: #eeeeee;
        }
    </style>
</head>
<body>
    <div id="app">
        <el-header height="90">
            <el-row class="title-box">
                <!-- <img src="{{ env('CDN_DOMAIN_NAME')}}/store/img/gommo.png" class="brand_logo" alt="" srcset=""> -->
                <span class="title"><b>@{{ cate_type }}</b> 热销榜</span>
            </el-row>
        </el-header>
        <el-main class="rank-box">
            <el-row class="rank-body">
                <el-col :span="5" :offset="1">
                    <div class="rank-title">
                        <span>TOP.</span><b>1</b>
                    </div>
                </el-col>
                <el-col :span="4" :offset="1">
                    <div class="rank-img">
                        <img :src="first[0].image">
                    </div>
                </el-col>
                <el-col :span="12">
                    <p class="rank-girard">@{{ first[0].girard }}</p>
                    <el-progress :show-text="false" :stroke-width="30" :percentage="first[0].percentage" status="exception"></el-progress>
                </el-col>
                <el-col :span="1"> </el-col>
            </el-row>
            <el-row class="rank-body">
                <el-col :span="5" :offset="1">
                    <div class="rank-title">
                        <span>TOP.</span><b>2</b>
                    </div>
                </el-col>
                <el-col :span="4" :offset="1">
                    <div class="rank-img">
                        <img :src="second[0].image" alt="" srcset="">
                    </div>
                </el-col>
                <el-col :span="12">
                    <p class="rank-girard">@{{ second[0].girard }}</p>
                    <el-progress :show-text="false" :stroke-width="30" :percentage="second[0].percentage" color="#f5c66c"></el-progress>
                </el-col>
                <el-col :span="1"> </el-col>
            </el-row>
            <el-row class="rank-body">
                <el-col :span="5" :offset="1">
                    <div class="rank-title">
                        <span>TOP.</span><b>3</b>
                    </div>
                </el-col>
                <el-col :span="4" :offset="1">
                    <div class="rank-img">
                        <img :src="third[0].image" alt="" srcset="">
                    </div>
                </el-col>
                <el-col :span="12">
                    <p class="rank-girard">@{{ third[0].girard }}</p>
                    <el-progress :show-text="false" :stroke-width="30" :percentage="third[0].percentage" color="#6cc3f5"></el-progress>
                </el-col>
                <el-col :span="1"> </el-col>
            </el-row>
        </el-main>
        <el-main class="rank-box-four">
            <el-row class="rank-body" v-for="item in data">
                <el-col :span="5" :offset="1">
                    <div class="rank-title">
                        <span>TOP.</span>
                        <b>@{{ item.id }}</b>
                    </div>
                </el-col>
                <el-col :span="3">
                    <div class="rank-img">
                        <img :src="item.image">
                    </div>
                </el-col>
                <el-col :span="13" :offset="1">
                    <p class="rank-girard">@{{ item.girard }}</p>
                    <el-progress :show-text="false" :stroke-width="30" :percentage="item.percentage" color="6cc3f5"></el-progress>
                </el-col>
            </el-row>
        </el-main>
    </div>
</body>
<script>
    function getQueryString(name) { 
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
        var r = window.location.search.substr(1).match(reg); 
        if (r != null) return unescape(r[2]); 
        return null; 
    } 
    var cdn_name = "{{ env('CDN_DOMAIN_NAME') }}";
    var app = new Vue({
        el:"#app",
        data(){
            return{
                cate_type:"",
                first:[{
                    girard:"",
                    percentage:0,
                    image:""
                }],
                second:[{
                    girard:"",
                    percentage:0,
                    image:""
                }],
                third:[{
                    girard:"",
                    percentage:0,
                    image:""
                }],
                data:[
                ],
            }
        },
        mounted(){
            let self = this;
            let cate_id = getQueryString('cate_id');
            $.ajax({
                headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                url: '/ranking/ranking-list-data',
                type: 'get',
                data: {
                    cate_id:cate_id
                },
                dataType: 'json',
                success: function(res) {
                    if(res.result.success){
                        let data = res.content.list;
                        let sum = res.content.num;
                        self.cate_type = res.content.name
                        self.first[0].girard = data[0].girard;
                        self.first[0].image = data[0].img_path;
                        self.first[0].percentage = Number(((200*Number(data[0].num)/Number(sum))).toFixed(0));
                        self.second[0].girard = data[1].girard;
                        self.second[0].image = data[1].img_path;
                        self.second[0].percentage = Number(((200*Number(data[1].num)/Number(sum))).toFixed(0));
                        self.third[0].girard = data[2].girard;
                        self.third[0].image = data[2].img_path;
                        self.third[0].percentage = Number(((200*Number(data[2].num)/Number(sum))).toFixed(0));
                        let checkFour = 0;
                        let fourData = [];
                        for(let value of data){
                            if(checkFour >2){
                                fourData.push({id:checkFour+1,girard:value.girard,image:self.checkImg(value.img_path),percentage:(Number(Number((200*Number(value.num)/Number(sum))).toFixed(0))+1)});
                            }
                            checkFour ++;
                        }
                        self.data = fourData;
                        setInterval(function(){
                            window.location.reload();
                        }, 120000);
                    }
                }
            });
        },
        methods:{
            checkImg(src){
                if(src == "请在操作选择图片"){
                    return cdn_name+"/bee/default.jpg"
                }else{
                    return src
                }
            }
        }
    })
</script>
</html>